Skip to content

Fix the PDF thumbnail example: convert page 1 straight to JPG - #56

Merged
tomasr78 merged 1 commit into
mainfrom
fix-pdf-thumbnail-example
Nov 9, 2026
Merged

tomasr78 merged 1 commit into
mainfrom
fix-pdf-thumbnail-example

Conversation

@tomasr78

@tomasr78 tomasr78 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The example cut page 1 out of the PDF with the extract converter and pagerange 1, then converted that page to JPG. pdf -> extract is now the AI data-extraction converter: it returns JSON and has no PageRange parameter (spec), so the second step gets a JSON file instead of page 1.

The Python example makes the same two calls and fails on production like this:

$ python create_pdf_thumbnail.py        # examples/ on main d653b60, production API, 2026-11-06
Traceback (most recent call last):
  ...
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://v2.convertapi.com/convert/json/to/jpg
  ...
convertapi.exceptions.ApiError: Parameter validation error. Code: 4000. {'SourceFormat, DestinationFormat': ['Unsupported conversion json -> jpg']}

Change

  • One pdf -> jpg call with pagerange 1 and imageheight 300 makes the thumbnail: one conversion instead of two. For test.pdf (US Letter) it is 231x300.
  • scaleimage and scaleproportions are dropped. They are not pdf -> jpg parameters (spec) and the API ignores them: the output is byte for byte the same with or without them.
  • The comment links only https://www.convertapi.com/pdf-to-jpg.

Verification

Compiled with ./mvnw -f examples/pom.xml compile against convertapi 2.13.1 from Maven Central, then run on OpenJDK 27.0.1 against the production API on 2026-11-06, in a folder holding files/test.pdf (a copy of examples/src/main/resources/test.pdf). $TMPDIR is the local temp folder:

$ java com.convertapi.examples.CreatePdfThumbnail
Creating PDF thumbnail
JPG thumbnail file saved to: $TMPDIR/test.jpg

test.jpg is 231x300 px, 8,858 bytes.

Not changed here: the comment in SplitAndMergePdf.java also links https://www.convertapi.com/pdf-to-extract, although that example uses split.

Only the example changes, not the library, so there is no CHANGELOG entry.

The thumbnail examples of the other SDKs are fixed in ConvertAPI/convertapi-library-python#61, ConvertAPI/convertapi-library-php#72, ConvertAPI/convertapi-library-ruby#42, ConvertAPI/convertapi-library-dotnet#82, ConvertAPI/convertapi-library-node#123.

🤖 Generated with Claude Code

pdf -> extract is now the AI data-extraction converter: it returns JSON
and has no PageRange, so the example's second step got a JSON file
instead of page 1. One pdf -> jpg call with pagerange=1 and
imageheight=300 now makes the thumbnail (231x300 for test.pdf), in one
conversion instead of two.

scaleimage and scaleproportions are dropped: they are not pdf -> jpg
parameters and the API ignored them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the direct PDF-to-JPG thumbnail update.

No open issues 🎉

What changed in this PR

Fixes the Java PDF thumbnail example by converting page 1 directly to JPG, avoiding the extract converter that now returns JSON.

Changes:

  • Replaces the two-step conversion with one PDF-to-JPG call using pagerange 1 and imageheight 300.
  • Removes unsupported scaleimage and scaleproportions parameters.
  • Updates the example’s comment and removes the extraction documentation link.
File Description
examples/​src/​main/​java/​com/​convertapi/​examples/​CreatePdfThumbnail.java Converts the first PDF page directly to a JPG thumbnail and updates the documentation comment.

Review effort: Balanced

@tomasr78
tomasr78 merged commit c16883c into main Nov 9, 2026
5 checks passed
@tomasr78
tomasr78 deleted the fix-pdf-thumbnail-example branch November 9, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants